package com.study.skywalking.dubbo.filter;

import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.rpc.*;
import org.apache.logging.log4j.ThreadContext;

/**
 * Created by zhangbo on 2020/6/8.
 */
@Slf4j
public class DubboProviderFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        try {
            log.debug("透传获取myTraceId");
            ThreadContext.put("myTraceId", invocation.getAttachment("myTraceId"));
            Result invoke = invoker.invoke(invocation);
            return invoke;
        } finally {
            ThreadContext.remove("myTraceId");
            log.debug("透传移传myTraceId");
        }
    }

}
